package com.atguigu.ssyx.sys.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.sys.RegionWare;
import com.atguigu.ssyx.sys.service.RegionWareService;
import com.atguigu.ssyx.vo.sys.RegionWareQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 开通区域 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-10-29
 */
@Api(tags = "开通区域")
@RestController
@RequestMapping("/admin/sys/regionWare")
public class RegionWareController {
    @Resource
    private RegionWareService regionWareService;

    // 查询开通区域列表
    @ApiOperation("查询开通区域列表")
    @GetMapping("{page}/{limit}")
    public Result findRegionWareList(@PathVariable Long page,
                                     @PathVariable Long limit,
                                     RegionWareQueryVo regionWareQueryVo) {
        Page<RegionWare> pageParam = new Page<>(page, limit);
        IPage<RegionWare> pageModel = regionWareService.selectPageRegionWare(pageParam, regionWareQueryVo);
        return Result.ok(pageModel);
    }

    // 添加开通区域
    @ApiOperation("添加开通区域")
    @PostMapping("save")
    public Result addRegionWare(@RequestBody RegionWare regionWare) {
        regionWareService.saveRegionWare(regionWare);
        return Result.ok(null);
    }

    // 取消开通区域
    @ApiOperation("取消开通区域")
    @PostMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id,
                               @PathVariable Integer status) {
        regionWareService.updateStatus(id, status);
        return Result.ok(null);
    }

    // 删除开通区域
    @ApiOperation("删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result removeRegionWare(@PathVariable Long id) {
        regionWareService.removeById(id);
        return Result.ok(null);
    }

    // 批量删除开通区域
    @ApiOperation("批量删除开通区域")
    @DeleteMapping("batchRemove")
    public Result batchRemoveRegionWare(@RequestBody List<Long> idList) {
        regionWareService.removeByIds(idList);
        return Result.ok(null);
    }
}

